/**
 * Created by IntelliJ IDEA.
 * User: p.popov
 * Date: 28.03.13
 * Time: 12:58
 * To change this template use File | Settings | File Templates.
 */
package slicesPanels {
public class ParametersValidator {
    public static function getFirstValidParameter(validationFunction:Function, parameters: Array):* {
        for each (var parameter:Object in parameters) {
            if (validationFunction(parameter)) {
                return parameter;
            }
        }
        throw new Error("all parameters aren't valid!");
    }

    public static function getIndexOfFirstValid(validationFunction:Function, parameters: Array):int {
        for ( var index : int = 0; index < parameters.length; index++ ) {
            var parameter:Object = parameters[index];
            if (validationFunction(parameter)) {
                return index;
            }
        }

//        var index:int = 0;
//        for each (var parameter:Object in parameters) {
//            if (validationFunction(parameter)) {
//                return index;
//            }
//            index++;
//        }
        throw new Error("all parameters aren't valid!");
    }

    public static function checkForNotNull(object:Object):Boolean {
        return object != null;
    }
}
}
